﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Performance considerations</title>
  <keywords>
    <keyword translate="true">Performance</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Performance considerations</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">While developer software, it is very important to keep an eye on the performance. Catel itself does perform very well, but there are some caveats that you should be aware of. If you have the feeling the the application is laggy or slow, or if you want to make sure to squeeze the best performance out of Catel, the checklist below is very important.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Disable the call to LogManager.RegisterDebugListener</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Logging_DebugLogListener" styleclass="Normal" translate="true">DebugListener</link><text styleclass="Normal" translate="true"> is a very useful class while developing an application. It throws all the logging of Catel to the output window of Visual Studio which allows you to view exactly what happens behind the scenes. However, writing all these logs to the output window is very expensive and might cause an application to perform badly.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Therefore, it is important to disable any call to </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Logging_LogManager_RegisterDebugListener" styleclass="Normal" translate="true">LogManager.RegisterDebugListener</link><text styleclass="Normal" translate="true"> when releasing an application or while performance testing.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Set SkipSearchingForInfoBarMessageControl on UserControl to true</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">By default, Catel assumes that an </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> is located on any window. However, it might be that this control is not located on a window that contains an instance of the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_UserControl" styleclass="Normal" translate="true">UserControl</link><text styleclass="Normal" translate="true"> class. This might decrease the performance, especially when lots of user controls are used in a hierarchical way. The cause is that the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_MVVMProviders_Logic_UserControlLogic" styleclass="Normal" translate="true">UserControlLogic</link><text styleclass="Normal" translate="true"> searches for an </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> to register the view model to.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">If no </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> is located on a container, make sure to set </text><link displaytype="text" defaultstyle="true" type="topiclink" href="P_Catel_Windows_Controls_UserControl_SkipSearchingForInfoBarMessageControl" styleclass="Normal" translate="true">SkipSearchingForInfoBarMessageControl</link><text styleclass="Normal" translate="true"> to </text><text styleclass="Normal" style="font-style:italic;" translate="true">true</text><text styleclass="Normal" style="font-style:normal;" translate="true">.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Disabling validation during activities where validation is not required</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Validation inside Catel is very powerful, but sometimes it is not needed. To disable all validation inside Catel, use the following code:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">ModelBase.SuspendValidationForAllModels</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">true</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">;</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Use LeanAndMeanModel property on ModelBase</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">When loading lots of models, it is not required to get support for validation and change notifications. Notifications and validation can be suspended per model (using the </text><text styleclass="Normal" style="font-style:italic;" translate="true">LeanAndMeanModel</text><text styleclass="Normal" translate="true"> property) or globally using the </text><text styleclass="Normal" style="font-style:italic;" translate="true">GlobalLeanAndMeanModel</text><text styleclass="Normal" translate="true"> property.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Use the FastObservableCollection</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><text styleclass="Normal" style="font-style:italic;" translate="true">FastObservableCollection</text><text styleclass="Normal" translate="true"> does not raise events for every item, but only invokes events for the complete range of items added to or removed from the collection.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Preloading assemblies into the AppDomain</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-style:normal;" translate="true">Preloading assemblies might result in a slower startup time, but will not cause slow downs for reflection or assembly loading during the actual application execution. To preload assemblies using Catel, simply call this extension method:</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">WPF application</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">In App.xaml.cs, add the following code</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">directory</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">typeof</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(MainWindow).Assembly.GetDirectory();</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">AppDomain.Current.PreloadAssemblies(directory);</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">ASP.NET application</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">In global.asax, add the following code:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">directory</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">Server.MapPath(&quot;~/bin&quot;);</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">AppDomain.Current.PreloadAssemblies(directory);</text></para>
  </body>
</topic>
